package com.dgut.legalservice.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class MyWebMvcConfiguration implements WebMvcConfigurer {
    @Autowired
    LoginHandleInterceptor loginHandleInterceptor;
    private List<String> url = new ArrayList();

    @Override
    public void addViewControllers(ViewControllerRegistry registry){
        registry.addViewController("/").setViewName("forward:/login");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);

    }

    public List<String> getUrl(){
        url.add("/login/login");      //登录页
        url.add("/login/register");   //登录action URL
        url.add("/login/registerSubmit");
        url.add("/center/sendEmail");
        url.add("/login/checkLoginName");
        url.add("/login/checkVcode");
        url.add("/login/checkEmail");
        url.add("/login/loginSubmit");
        //网站静态资源
        url.add("/login/checkPassword");
        url.add("/css/**");
        url.add("/js/**");
        url.add("/font/**");
        url.add("/fonts-awesome-4.7.0/**");
        url.add("/icon-reference/**");
        url.add("/img/**");
        url.add("/other/**");
        url.add("/Front-Admin/**");
        return url;
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry){
      registry.addInterceptor(loginHandleInterceptor).addPathPatterns("/**").excludePathPatterns(getUrl());
    }

}
